package generic.page;

import java.util.List;

/**
 * 页码参数
 */
public class Page {
    private int pageSize;//每页上的记录数.不能为零
    private int totalPage;//总页数
    private int rowCount; //总记录数
    private int currentPage; //当前页码
    private int offset;//当前开始记录的位置
    private List list; //返回的记录列表

    public Page(){

    }

    public Page(int pageSize,int currentPage,int rowCount){
        this.pageSize=pageSize;
        this.rowCount=rowCount;
        this.setTotalPage(totalPage);
        this.setCurrentPage(currentPage);
        this.setOffset(offset);
    }


    public int getOffset() {
        return offset;
    }

    public void setOffset(int offset) {
        offset=pageSize * (currentPage - 1);
        if(offset >0){
            this.offset=offset;
        }else{
            this.offset = 0;
        }
    }


    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public List getList() {
        return list;
    }

    public void setList(List list) {
        this.list = list;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        if (currentPage > totalPage)
        {
            this.currentPage = totalPage ;
        }else {
            this.currentPage = currentPage <= 0 ? 1 : currentPage ;
        }
    }

    public int getRowCount() {
        return rowCount;
    }

    public void setRowCount(int rowCount) {
        this.rowCount = rowCount;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = rowCount % pageSize == 0 ? rowCount/pageSize : rowCount/pageSize + 1;
    }

}